<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Minha Colecao de CDs</title>
        <!--<script language="javascript" src="funcoes.js"></script>-->
        <script type="text/javascript" >
            var dados;
            var discos;
            var a;
            function abrir(arquivo){
                if (window.XMLHttpRequest) {
                    xmlhttp=new XMLHttpRequest();
                } else{
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.open("GET",arquivo,false);
                xmlhttp.send();
                return xmlhttp.responseXML;
            }
            function listar(){
                dados = abrir("discos.xml");
                t = dados.documentElement;
                a = t.firstChild.nextSibling;
                //                a = discos.firstChild.nextSibling;
                primeiro();
                //    var mostrar = "";
                //    discos=dados.getElementsByTagName("cds");
            }
            function last(acao){
    
                if(acao==0){
                    
                    a = t.firstChild.nextSibling;
                    
                }else if(acao == 1){
                    if(a == t.firstChild.nextSibling){
                        alert("Já é o primeiro");
                    }else{
                        a = a.previousSibling.previousSibling;
                    }
                }else if(acao == 2){
                    if(a == t.lastChild.previousSibling){
                        alert("Ja é o ultimo");
                    }else{
                        a = a.nextSibling.nextSibling;
                    }
                }else{
                    
                    a=t.lastChild.previousSibling;
                    
                }
                //    alert("a" + a.nodeName);
    
                primeiro();
            }

            function primeiro(){
                for(i=1; i<a.childNodes.length; i=i+2){
                    if(i==7){
                        j = 1;
                        var la = a.childNodes[i].childNodes.length;
                        while(j<la){
                            alert(a.childNodes[i].childNodes[j].childNodes[0].nodeValue);
                            j = j + 2;
                        }
                    }else{
                        alert(a.childNodes[i].childNodes[0].nodeValue);
                    }
                }
            }    
        </script>
    </head>
    <body onload="listar();">
        <?php ?>
        <div id="principal">
            <div id="botoes">
                <button onclick="last(0);">Primeiro</button>
                <button onclick="last(1);">Anterior</button>
                <button onclick="last(2);">Proximo</button>
                <button onclick="last(3);">Ultimo</button>


            </div>
            <div id="exibir"></div> 

        </div>
        fff
    </body>
</html>
